const { log } = require('console')
const http = require('http')
const port = 4800
const hostname = '0.0.0.0'
const url = require('url')

const route = require('./route')

const server = http.createServer((req, res) => {
    if (req.url != './favicon.ico') {
        const urls = url.parse(req.url)

        const pathname = urls.pathname.replace(/\//, '')
        console.log(pathname);
        try {
            route[pathname](req, res)

        } catch (err) {
            route['notfound'](req, res)
        }
    }
})
    .listen(port, hostname, () => {
        console.log(`this server is running at http://${hostname}:${port}`)
    })